<template>
<div id="Shenghuohui">
  <el-dialog title="查看退回原因" :visible.sync="dialogVisible" width="50%" top="20px" :close-on-click-modal="false" :close-on-press-escape="false" append-to-body>
    {{operateUserName}} [{{operateTime}}] ：<b>{{remark}}</b>
  </el-dialog>
  <el-breadcrumb separator=">">
    <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
    <el-breadcrumb-item>民主生活会数据填报</el-breadcrumb-item>
  </el-breadcrumb>
  <section class="wboxd" style="margin-top:10px">
    <el-table :data="shhlist" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border>
      <el-table-column type="index" label="序号" width="70" align="center">
      </el-table-column>
      <el-table-column prop="theYear" label="年度" width="120" align="center">
      </el-table-column>
      <el-table-column prop="name" label="标题">
      </el-table-column>
      <el-table-column label="状态" width="200" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.flowType===1">填报</span>
          <span v-else-if="scope.row.flowType===3">退回</span>
          <el-button size="small" v-if="scope.row.flowType===3" @click="showBack(scope.row)">查看原因</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="500">
        <template slot-scope="scope">
          <el-button size="small" type="primary" style="margin:10px 0" @click="shhshow(scope.row)">进入填报</el-button>
          <el-button size="small" type="success"  style="margin:10px 0" @click="submitData(scope.row.shenghuohuiunitId)">提交</el-button>
        </template>
      </el-table-column>
    </el-table>
  </section>
</div>
</template>

<script>
export default {
  data () {
    return {
      dialogVisible: false,
      remark: '',
      operateTime: '',
      operateUserName: '',
      tableHeight: 100,
      maxId: 0,
      isAdmin: true, // 临时调整为true
      isChuzhang: false,
      editVisible: false,
      editBtnsVisible: true,
      shhlist: [],
      listLoading: false,
      totalnum: 0,
      addFormVisible: false, // 新增界面是否显示
      addLoading: false,
      // 新增界面数据
      addForm: {
        Name: '',
        TheYear: ''
      },
      addFormRules: {
        Name: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        TheYear: [
          { required: true, message: '请选择年度', trigger: 'blur' }
        ]
      },
      editFormRules: {
        Name: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        TheYear: [
          { required: true, message: '请选择年度', trigger: 'blur' }
        ]
      },
      editFormVisible: false, // 编辑界面是否显示
      editLoading: false,
      // 编辑界面数据
      editForm: {
        Name: '',
        TheYear: '',
        Id: 0
      }
    }
  },
  methods: {
    showBack (data) {
      this.dialogVisible = true
      this.operateUserName = data.operateUserName
      this.operateTime = data.operateTime
      this.remark = data.remark
    },
    submitData (id) {
      this.$confirm('确认已填写完成，提交该生活会信息吗?', '提示', {
        type: 'warning'
      }).then(() => {
        let para = {
          shenghuohuiunitId: id
        }
        this.$http.post(this.$http.defaults.shenghuohuiAPI + `api/newFlow/saveSubmit`, para).then(response => {
          console.log(response.data.success)
          if (response.data.success === true) {
            this.btnLoading = false
            this.$message({
              message: '提交成功',
              type: 'success'
            })
            this.getShh()
          } else {
            console.log('提交失败:' + response.data.message)
            this.$message({
              message: '提交失败:' + response.data.message,
              type: 'error'
            })
            this.btnLoading = false
          }
        }).catch(error => {
          console.log(error)
          this.$message({
            message: '提交失败:' + error,
            type: 'error'
          })
          this.btnLoading = false
        })
      })
    },
    shhshow (data) {
      console.log(data.theyYear)
      localStorage.setItem('shenghuohuiunitId', data.shenghuohuiunitId)
      localStorage.setItem('shenghuohuiId', data.shenghuohuiId)
      if (data.theYear === 2021) {
        this.$router.push({name: `unitShenghuohui`})
      } else if (data.theYear === 2022) {
        this.$router.push({name: `unitShenghuohui2022`})
      } else if (data.theYear === 2023) {
        this.$router.push({name: `unitShenghuohui2023`})
      } else if (data.theYear >= 2024) {
        this.$router.push({name: `unitShenghuohui2024`})
      }
    },
    // 获取用户列表
    getShh () {
      this.listLoading = true
      this.$http.post(this.$http.defaults.shenghuohuiAPI + `api/newFlow/getCurrentTopFlows`, {}).then(response => {
        if (response.data.success === true) {
          this.listLoading = false
          this.shhlist = response.data.result
        } else {
          this.listLoading = false
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 162
      })
    }
  },
  mounted () {
    this.getShh()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #testlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  .el-table--border th, .el-table--border td {
    border-right: 1px solid #95B8E7;
  }
  .el-table th.is-leaf, .el-table td {
    border-bottom: 1px solid #95B8E7;
  }
  #Shenghuohui .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }

</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
